// 筛选获取当前页的菜单 （路由）
function getBtnShow(routh, roleListBtn) {
  if (!Array.isArray(roleListBtn)) {
    roleListBtn = []
  }
  const data = roleListBtn.filter((item) => {
    if (item.url === routh) {
      return item
    }
  })
  return data ? data[0] ? data[0].rulesBtn : [] : []
}
// 筛选获取右键的菜单
function rightBtnShow (oldBtn, allBtn) {
  if (!Array.isArray(oldBtn)) {
    oldBtn = []
  }
  if (!Array.isArray(allBtn)) {
    allBtn = []
  }
  const newdata = []
  for (let i = 0; i < allBtn.length; i++) {
    const data = oldBtn.filter((item) => {
      return item.perms === allBtn[i].perms
    })
    if (data.length > 0) {
      newdata.push(data[0])
    }
  }
  newdata.sort((a, b) => {
    return a.id - b.id
  });
  return newdata
}
// 判断是否存在list
function oneBtnShow (name, list) {
  if (!Array.isArray(list)) {
    list = []
  }
  for (let i = 0; i < list.length; i++) {
    if (list[i].perms === name) {
      return true
    }
  }
  return false
}

export {
  getBtnShow, rightBtnShow, oneBtnShow
}
